package com.itheima.aspect;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

//演示AOP中的5种通知方法
@Slf4j
//@Aspect
@Component
public class AspectDemo1 {

    //环绕通知
    @SneakyThrows
    @Around("execution(public * com.itheima.service.*.*(..))")
    public Object m1(ProceedingJoinPoint pjp) {
        log.info("环绕前通知:{}", pjp.getSignature());
        Object result = pjp.proceed(); //控制原始方法执行
        log.info("环绕后通知:{}", pjp.getSignature());
        return result;
    }

    //前置通知
    @Before("execution(public * com.itheima.service.*.*(..))")
    public void m2(JoinPoint jp) {
        log.info("前置通知:{}", jp.getSignature());
    }

    //最终通知（不管有没有异常，都执行）
    @After("execution(public * com.itheima.service.*.*(..))")
    public void m3(JoinPoint jp) {
        log.info("最终通知:{}", jp.getSignature());
    }

    //后置通知
    @AfterReturning("execution(public * com.itheima.service.*.*(..))")
    public void m4(JoinPoint jp) {
        log.info("后置通知:{}", jp.getSignature());
    }

    //异常通知
    @AfterThrowing("execution(public * com.itheima.service.*.*(..))")
    public void m5(JoinPoint jp) {
        log.info("异常通知:{}", jp.getSignature());
    }



}